from models.dept import Dept
from services import BaseService
from tools import build_tree
from tools.db_tool import DbTool
from sqlalchemy import asc


class DeptService(BaseService):
    """
    部门模块业务处理类
    """

    def list(self):
        """
        部门列表
        """
        list = DbTool.filter_by_custom(Dept).order_by(asc(Dept.sort)).all()
        return Dept.to_dict_list(list)

    def tree(self):
        """
        部门树
        """
        list = DbTool.filter_by_custom(Dept).order_by(asc(Dept.sort)).all()
        return build_tree(Dept.to_dict_list(list))
